package com.example.testcontent;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
import android.net.Uri;
import android.util.Log;

public class MyContentProvider extends ContentProvider {
    static UriMatcher _matcher;
    static String _data;

    static {
        _matcher = new UriMatcher(UriMatcher.NO_MATCH);

        _matcher.addURI("com.example.testcontent", "test", 1);

        Log.d("provider", "static");
    }

    public MyContentProvider() {
        Log.d("provider", "construct");
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        // Implement this to handle requests to delete one or more rows.
        Log.d("provider", "delete");
        _data = "";
        return 0;
    }

    @Override
    public String getType(Uri uri) {
        // TODO: Implement this to handle requests for the MIME type of the data
        // at the given URI.
        Log.d("provider", "getType");
        return "";
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        // TODO: Implement this to handle requests to insert a new row.
        int code = _matcher.match(uri);
        if (code == -1)
            return null;

        Log.d("provider", "insert");

        if (values.containsKey("provider")) {
            String val = values.get("provider").toString();
            Log.d("provider", "insert " + val);
        }
        if (values.containsKey("main")) {
            String val = values.get("main").toString();
            Log.d("provider", "insert " + val);
        }

        return null;
    }

    @Override
    public boolean onCreate() {
        // TODO: Implement this to initialize your content provider on startup.
        return false;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
                        String[] selectionArgs, String sortOrder) {
        // TODO: Implement this to handle query requests from clients.
        int code = _matcher.match(uri);
        if (code == -1)
            return null;

        switch (code) {
            case 1:
                Log.d("provider", "query 1");
                break;
            default:
                Log.w("provider", "unknown");
                break;
        }

        return null;
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection,
                      String[] selectionArgs) {
        // TODO: Implement this to handle requests to update one or more rows.
        int code = _matcher.match(uri);
        if (code == -1)
            return -1;

        Log.d("provider", "update");

        return 0;
    }
}